<!DOCTYPE html>
<html lang="zh_CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var duck = {
        name: "鸭子",
        duckSinging: function () {
          console.log("嘎嘎嘎");
        },
      };

      var chicken = {
        name: "公鸡",
        duckSinging: function () {
          console.log("嘎嘎嘎");
        },
      };

      var choir = [];

      var joinChoir = function (animal) {
        if (animal && typeof animal.duckSinging === "function") {
          choir.push(animal);
          console.log(`恭喜: ${animal.name} 加入鸭子合唱团`);
          console.log(`鸭子合唱团当前人数：${choir.length}`);
        }
      };

      joinChoir(duck);
      joinChoir(chicken);
    </script>
  </body>
</html>
